package com.systemsjr.jrbbf.common;

import net.rim.device.api.command.Command;
import net.rim.device.api.command.CommandHandler;
import net.rim.device.api.command.ReadOnlyCommandMetadata;
import net.rim.device.api.database.Database;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.util.StringProvider;

import com.systemsjr.jrbbf.ExpenseUI;
import com.systemsjr.jrbbf.db.SQLManager;
import com.systemsjr.jrbbf.expense.ExpenseList;
import com.systemsjr.jrbbf.expense.ExpenseScreen;
import com.systemsjr.jrbbf.expense.ExpenseTypeList;
import com.systemsjr.jrbbf.expense.ExpenseTypeScreen;
import com.systemsjr.jrbbf.expense.ManageExpense;
import com.systemsjr.jrbbf.expense.ManageExpenseType;

public abstract class ExpenseManagerScreen extends MainScreen{
	protected SQLManager sqlManager;
	public static Database db;
	protected ExpenseUI app = (ExpenseUI) UiApplication.getUiApplication();
	
	protected MenuItem addExpenseType(){
		MenuItem addType = new MenuItem(new StringProvider("Add Expense Type"), 0x230010, 0);
		
		addType.setCommand(new Command(new CommandHandler() {
			
			public void execute(ReadOnlyCommandMetadata metadata, Object context) {
				UiApplication app = UiApplication.getUiApplication();
                app.pushModalScreen(new ExpenseTypeScreen(new ManageExpenseType(ExpenseManagerScreen.db))); 				
			}
		}));
		
		return addType;
	}
	
	protected MenuItem addExpense(){
		MenuItem addType = new MenuItem(new StringProvider("Add Expense"), 0x230010, 0);
		
		addType.setCommand(new Command(new CommandHandler() {
			
			public void execute(ReadOnlyCommandMetadata metadata, Object context) {
				UiApplication app = UiApplication.getUiApplication();
                app.pushModalScreen(new ExpenseScreen(new ManageExpense(ExpenseManagerScreen.db))); 				
			}
		}));
		
		return addType;
	}
	
	protected MenuItem exipApp(){
		MenuItem close = new MenuItem(new StringProvider("Exit"), 0x230010, 0);
		close.setCommand(new Command(new CommandHandler() {
			
			public void execute(ReadOnlyCommandMetadata metadata, Object context) {
				onClose();
			}
		}));
		
		return close;
	}
	
	protected MenuItem reload(){
		MenuItem reload = new MenuItem(new StringProvider("Refresh"), 0x230010, 0);
		reload.setCommand(new Command(new CommandHandler() {
			
			public void execute(ReadOnlyCommandMetadata metadata, Object context) {
				doReload();
			}
		}));
		
		return reload;
	}
	
	protected void doReload() {}

	protected MenuItem viewExpenseTypes(){
		MenuItem view = new MenuItem(new StringProvider("View All"), 0x230010, 0);
		view.setCommand(new Command(new CommandHandler() {
			
			public void execute(ReadOnlyCommandMetadata metadata, Object context) {
				ExpenseUI app = (ExpenseUI) UiApplication.getUiApplication();
                app.pushModalScreen(new ExpenseTypeList(new ManageExpenseType(ExpenseManagerScreen.db)));
			}
		}));
		
		return view;
	}
	
	protected MenuItem viewExpenses(){
		MenuItem view = new MenuItem(new StringProvider("View All"), 0x230010, 0);
		view.setCommand(new Command(new CommandHandler() {
			
			public void execute(ReadOnlyCommandMetadata metadata, Object context) {
				ExpenseUI app = (ExpenseUI) UiApplication.getUiApplication();
                app.pushModalScreen(new ExpenseList(new ManageExpense(ExpenseManagerScreen.db)));
			}
		}));
		
		return view;
	}
}
